﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Summerset.Isbndb.Books
{
    /// <summary>
    /// An additional result that contains information about an author of a publication.
    /// Additional information about this author can be retrieved by using the PersonId 
    /// property to query authors collection.
    /// </summary>
    public sealed class BookElementAuthor
    {
        /* 
        Example Element:
        <Authors>
            <Person person_id="mishra_vishwa_mohan">Mishra, Vishwa Mohan</Person>
        </Authors> 
        */

        #region Constructor + Private Fields

        readonly XmlNode _personNode;

        /// <summary>
        /// Creates a new instance of a book element author.
        /// </summary>
        /// <param name="personNode">The xml element that contains the underlying information for this object.</param>
        public BookElementAuthor(XmlNode personNode)
        {
            _personNode = personNode;
        }

        #endregion
        #region Properties

        /// <summary>
        /// Gets an ISBNdb-specific id that represents this person.
        /// </summary>
        public string PersonId
        {
            get
            {
                return _personNode.Attributes["person_id"].Value;
            }
        }

        /// <summary>
        /// Gets a friendly name that identifies this person.  This value can be displayed to users.
        /// </summary>
        public string PersonText
        {
            get
            {
                return _personNode.InnerText;                
            }
        }

        #endregion
    }
}
